import sys, os
parentPath = os.path.abspath('..')
if not parentPath in sys.path:
sys.path.append(parentPath)
from presentation import hide_code_button
hide_code_button()
import pandas as pd
import numpy as np
import analysis
from presentation import markprint
from functools import partial
average = analysis.average
%matplotlib inline
frm = analysis.make_melvic_dataFrm()
cases = analysis.make_casesFrm()
avStay = average(frm, 'adjstay')
rollingAvStay = avStay.rolling(7).mean().dropna()
stayScoreAv = average(frm, 'stayscore')
rollingScores = frm.reset_index().set_index(['date', 'name'])['stayscore'].rolling(7).mean()
maxDate = rollingScores.index.get_level_values('date').max()
lgaScores = pd.DataFrame(rollingScores.loc[maxDate]).reset_index()
lgaScores = lgaScores.rename(dict(stayscore = 'Score', name = 'LGA'), axis = 1)
lgaScores = lgaScores.set_index('LGA')
bestFive, worstFive = lgaScores.nlargest(5, 'Score'), lgaScores.nsmallest(5, 'Score')
These plots, based on Facebook location tracking data, show the changes in patterns of movement of tense of thousands of Facebook users in response to the COVID-19 pandemic. The data has been aggregated to Local Government Areas, typically city councils.
The stay-put quantity reflects the number of records provided by Facebook which show people moving beyond their immediate vicinity (about one kilometre in any direction), adjusted slightly for known sampling biases. The population-weighted average stay-put quantity has been plotted along with a seven-day rolling average, which smooths out daily variations. The horizontal axes are given in weeks starting Sundays.
Because of privacy concerns, Facebook's data is aggressively pruned wherever population counts are low, which leads to serious underestimates of movement for less densely populated areas. To correct this we have created a Lockdown Score, which normalises every value based off the averages of the best and worst values observed for that day of the week for that council. A score of one or higher indicates that people are equalling or exceeding their best ever stay-at-home behaviours. A score of zero or lower indicates that people are matching or trailing their worst ever behaviours. A weighted average lockdown score has been plotted, as well as the complete data for all councils below it.
For comparison, the new daily cases have been plotted at the bottom, while letter annotations correspond to the major changes in public perceptions and policies, as well as public holidays.
Full data, additional aggregations, and interactive plots are available on the website. The data are updated daily and the portal is continually being improved. If you have questions or suggestions, please contact Rohan Byrne.
This work is a collaboration with Professor Sally Cripps, Dr Roman Marchant, and Dr Vincent Chin of the DARE Centre and Rohan Byrne of the University of Melbourne with funding from the Australian Research Council (FT140101266).
from window.plot import Canvas, Data, get_cmap
dates = frm.index.get_level_values('date')
events_annotate = partial(
analysis.events_annotate,
region = 'vic',
lims = (dates.min(), dates.max()),
points = (0, 12)
)
markprint('## Summary')
markprint('---')
ax = Canvas(size = (12, 3)).make_ax()
ax.set_title('Stay-put ratio: Melbourne average with 7-day rolling average')
ax.line(
avStay.index,
Data(avStay.values),
)
ax.line(
Data(rollingAvStay.index, label = 'Date'),
Data(rollingAvStay.values, label = 'Proportion staying put'),
)
table = events_annotate(ax, avStay)
markprint(table)
markprint('---')
display(ax.canvas.fig)
markprint('---')
ax = Canvas(size = (12, 3)).make_ax()
ax.set_title('Lockdown score: Melbourne average')
ax.line(
Data(stayScoreAv.index, label = 'Date'),
Data(stayScoreAv.values, label = 'Average stay-put score'),
)
keystr = events_annotate(ax, stayScoreAv)
display(ax.canvas.fig)
markprint('---')
ax = Canvas(size = (12, 3)).make_ax()
ax.set_title('Lockdown score: Melbourne LGAs')
xs, ys, cs, ss, ls = [], [], [], [], []
cmap = get_cmap('gist_ncar')
for i, name in enumerate(sorted(set(frm['name']))):
subFrm = frm.loc[frm['name'] == name]
series = subFrm.reset_index().set_index('date')['stayscore']
series = series.dropna()
xs.append(Data(series.index, label = 'Date'))
ys.append(Data(series.values, label = 'Score', lims = (-1., 2.)))
cs.append(cmap(i / len(set(frm['name'])), alpha = 0.5))
ss.append(None)
ls.append(name)
ax.multiline(xs, ys, cs, ss, ls)
axPoints = frm.reset_index().groupby('date')['stayscore'].apply(max)
keystr = events_annotate(ax, axPoints)
ax.ax.legend(
loc = 'lower left',
# bbox_to_anchor = (0.5, -0.5),
# ncol = 5,
# bbox_to_anchor = (0.24, 0.52),
ncol = 6,
prop = dict(size = 6),
fancybox = True,
# shadow = True,
framealpha = 0.5,
)
display(ax.canvas.fig)
markprint('---')
ax = Canvas(size = (12, 3)).make_ax()
ax.set_title('Victorian daily active cases since the second wave')
sumCases = cases.groupby(cases.index.get_level_values('date'))['active'].sum()
ax.line(
Data(sumCases.index, label = 'Date', lims = ('2020-04-12', stayScoreAv.index.max())),
Data(sumCases.values, label = 'Active cases'),
)
keystr = events_annotate(ax, sumCases)
display(ax.canvas.fig)
markprint('---')
markprint("### Average scores for the past week per LGA:")
display(lgaScores)
markprint("#### Best five scores for past week:")
display(bestFive)
markprint("#### Worst five scores for past week:")
display(worstFive)
markprint('## Breakdown by LGA')
for name in sorted(set(frm['name'])):
markprint(f'### {name}')
subFrm = frm.loc[frm['name'] == name]
subFrm = subFrm.reset_index().set_index('date')
subStay = subFrm['adjstay'].dropna()
rollingSubStay = subStay.rolling(7).mean().dropna()
subScore = subFrm['stayscore'].dropna()
dates = frm.index.get_level_values('date')
minDate, maxDate = dates.min(), dates.max()
ax = Canvas(size = (12, 3)).make_ax()
ax.set_title('Stay-put ratio: average with 7-day rolling average')
ax.line(
Data(subStay.index, lims = (minDate, maxDate)),
Data(subStay.values, lims = (None, 1.)),
)
ax.line(
Data(rollingSubStay.index, label = 'Date', lims = (minDate, maxDate)),
Data(rollingSubStay.values, label = 'Proportion staying put'),
)
keystr = events_annotate(ax, subStay)
display(ax.canvas.fig)
ax = Canvas(size = (12, 3)).make_ax()
ax.set_title('Lockdown score')
ax.line(
Data(subScore.index, label = 'Date', lims = (minDate, maxDate)),
Data(subScore.values, label = 'Stay-put score'),
)
keystr = events_annotate(ax, subScore)
display(ax.canvas.fig)
ax = Canvas(size = (12, 3)).make_ax()
ax.set_title('Daily active cases since the second wave')
subCases = cases.xs(name, level = 'name')['active'].dropna()
ax.line(
Data(subCases.index, label = 'Date', lims = ('2020-04-12', maxDate)),
Data(subCases.values, label = 'Active cases'),
)
display(ax.canvas.fig)
markprint('---')